<template>
  <!-- 点云分割目标选择对话框 -->
  <el-dialog title="选择待修改目标" :visible.sync="localVisible" width="480px" append-to-body>
    <el-form ref="updateSplitInfoForm" :model="model" label-width="160px">
      <el-form-item label="类型" prop="name">
        <el-select v-model="model.mMarkAnnotationId" placeholder="请选择类型">
          <el-option
            v-for="item in annotationList"
            :key="item.mMarkAnnotationId"
            :label="annotationNameFormatter(item)"
            :value="item.mMarkAnnotationId"
          />
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleOk">确 定</el-button>
      <el-button @click="handleCancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'PcdObjectDialog',
  props: {
    // updateSplitInfoDialogOpen
    visible: { type: Boolean, default: false },
  },
  data() {
    return {
      // updateSplitInfoForm
      model: {},

      // annotationList
      annotationList: [],
    }
  },
  created() {},
  computed: {
    localVisible: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      },
    },
  },

  methods: {
    open() {},

    annotationNameFormatter(row) {
      let jsonObject = JSON.parse(this.selectDictLabel(this.attributeNames, 'labelName'))
      if (jsonObject.values.hasOwnProperty(row.name)) return jsonObject.values[row.name]
      else return row.name
    },

    // submitUpdateSplitInfoForm() {
    handleOk() {
      let tobeUpdated = null
      this.annotationList.forEach((element) => {
        if (element.mMarkAnnotationId == this.model.mMarkAnnotationId) tobeUpdated = element
      })
      let originalPointsIndex = tobeUpdated.x.split(',')
      let tmpPoints = []
      originalPointsIndex.forEach((index) => {
        if (this.model.minusPointsIndex.indexOf(parseInt(index)) == -1) tmpPoints.push(parseInt(index))
      })
      this.model.pointsIndex.forEach((index) => {
        if (tmpPoints.indexOf(index) == -1) tmpPoints.push(index)
      })
      tobeUpdated.x = tmpPoints.toString()

      // updateAnnotation(tobeUpdated).then(response => {
      //   if (response.code == 200) {
      //     // this.updateSplitInfoForm.callback(params);
      //     this.msgSuccess('更新成功')
      //     this.removeCache(this.fileList[this.currentIndex].mQaResultId)
      //     this.changePage(0)
      //   } else {
      //     this.msgError(response.msg)
      //   }
      //   this.updateSplitInfoDialogOpen = false
      // })

      this.$emit('onOk', tobeUpdated)
      this.$emit('update:visible', false)
    },

    // cancelUpdateSplitInfoForm() {
    handleCancel() {
      if (this.model.callback) {
        const params = {
          form: null,
          ret: 'cancel',
        }
        this.model.callback(params)

        this.$emit('update:visible', false)
        this.$emit('onCancle', null)
      }
    },
  },
}
</script>

<style></style>
